/*
* 存储菜单和路由
* */

import router from '@/router/index.js';
export default {
    namespaced: true,
    state: {
        caidan: [
            {
                name:"个人",
                id:"1",
                children:[
                    {name:"首页",pathName:"Shouye",id:"10",},
                    {name:"发起流程",pathName:"",id:"1001",},
                    {name:"我的考勤",pathName:"Attendances",id:"1002",},
                    {name:"我的申请",pathName:"",id:"1003",},
                    {name:"待办任务",pathName:"",id:"1004",},
                    {name:"资产管理",pathName:"",id:"1005",},
                    {name:"知识管理",pathName:"",id:"1006",},
                    {name:"邮件",pathName:"Email",id:"1007",},
                    {name:"通讯录",pathName:"Addresslist",id:"1008",},
                    {name:"日程管理",pathName:"",id:"1009",},
                    {name:"我的相册",pathName:"Photoalbum",id:"1010",},
                    {name:"文件仓库",pathName:"",id:"1011",},
                    {name:"便签",pathName:"Note",id:"1012",},
                ],
            },
            {
                name:"资产",
                id:"2",
                pathName:"",
                children:[
                    {name:"办公设备",pathName:"",id:"2001",},
                    {name:"车辆管理",pathName:"",id:"2002",},
                    {name:"电子设备",pathName:"",id:"2003",},
                    {name:"消耗品",pathName:"",id:"2004",},
                    {name:"印章管理",pathName:"",id:"2005",},
                    {name:"公文管理",pathName:"",id:"2006",},
                    {name:"食堂管理",pathName:"",id:"2007",},
                    {name:"接待管理",pathName:"",id:"2008",},
                    {name:"会议室",pathName:"",id:"2009",},
                    {name:"工服",pathName:"",id:"2010",},
                    {name:"宿舍管理",pathName:"",id:"2011",},
                    {name:"卫生管理",pathName:"",id:"2012",},
                    {name:"维修管理",pathName:"",id:"2013",},
                    {name:"政府关系",pathName:"",id:"2014",},
                ],
            },
            {
                name:"通知",
                id:"3",
                pathName:"",
                children:[
                    {name:"通知公告",pathName:"",id:"3001",},
                    {name:"规章制度",pathName:"",id:"3002",},
                    {name:"知识管理",pathName:"",id:"3003",},
                    {name:"投票调查",pathName:"",id:"3004",},
                    {name:"互动论坛",pathName:"",id:"3005",},
                ],
            },
            {
                name:"人事",
                id:"4",
                pathName:"",
                children:[
                    {name:"人员档案",pathName:"",id:"4001",},
                    {name:"考勤异常",pathName:"",id:"4002",},
                    {name:"加班管理",pathName:"",id:"4003",},
                    {name:"请假管理",pathName:"",id:"4004",},
                    {name:"出差管理",pathName:"",id:"4005",},
                    {name:"转正管理",pathName:"",id:"4006",},
                    {name:"离职管理",pathName:"",id:"4007",},
                    {name:"薪资调整",pathName:"",id:"4008",},
                    {name:"人事调动",pathName:"",id:"4009",},
                    {name:"人员培训",pathName:"",id:"4010",},
                    {name:"合同管理",pathName:"",id:"4011",},
                    {name:"员工关怀",pathName:"",id:"4012",},
                    {name:"人力需求",pathName:"",id:"4013",},
                ],
            },
            {
                name:"财务",
                id:"5",
                pathName:"",
                children:[

                ],
            },
            {
                name:"客户",
                id:"6",
                pathName:"",
                children:[

                ],
            },
            {
                name:"项目",
                id:"7",
                pathName:"",
                children:[

                ],
            },
            {
                name:"流程",
                id:"8",
                pathName:"",
                children:[

                ],
            },
            {
                name:"系统",
                id:"9",
                pathName:"",
                children:[
                    {name:"组织结构",pathName:"Structure",id:"9001",},
                    {name:"角色权限",pathName:"Permission",id:"9002",},
                    {name:"公司信息",pathName:"Company",id:"9003",},
                ],
            },
            {
                name:"平台管理",
                id:"999",
                pathName:"",
                children:[

                ],
            },
        ],
        luyou: [],
        activeindex1:0,
        activeindex2:"",
        selectmenu:[],
    },
    getters:{
    },
    mutations: {
        // 将菜单数据保存到vuex
        setcaidan(state, payload) {
            console.log("排序")
            console.log("插入")
        },
        // 将菜单数据保存到vuex
        setluyou(state, payload) {
            console.log("排序")
            console.log("插入")
        },
        // 点击顶部导航菜单
        changeactiveIndex1(state, payload){
            state.activeindex1 = payload
            console.log("点击顶部菜单",payload,state.activeindex1)
        },
        // 点击侧边菜单,将点击的菜单存放到激活的菜单列表里。
        clickmenu(state,payload){
            console.log("点击侧边菜单",payload)
            state.activeindex2 = payload.id
            // 将菜单放到激活列表里面
            let jieguo = true
            for(let i=0;i<state.selectmenu.length;i++){
                if(state.selectmenu[i].id===payload.id){
                    jieguo = false
                    break
                }
            }
            if(jieguo){
                state.selectmenu.push(payload)
            }
            router.push({name:payload.pathName})
        },
        // 重置数据
        reststate(state) {
            state.caidan = []
            state.luyou = []
            state.activeindex1 = "-1"
            state.activeindex2 = ""
            state.selectmenu = []
        }
    },
    actions: {
        // 关闭激活的菜单
        closemenu(content,payload){
            content.state.selectmenu.splice(payload,1)
            if(payload === content.state.activeindex2){
                if(content.state.selectmenu[payload]){
                    content.commit("clickmenu",content.state.selectmenu[payload])
                }else if(content.state.selectmenu[payload-1]){
                    content.commit("clickmenu",content.state.selectmenu[payload-1])
                }
            }
            content.dispatch("sendshouye")
        },
        // 如果列表空了，将首页添加进去
        sendshouye(content){
            if(content.state.selectmenu.length === 0){
                const item = content.state.caidan[0].children[0]
                content.commit("clickmenu",item)
            }
        },
    },
}



